package Sort;

import java.util.Arrays;

/**
 * @Classname JZ45把数组排成最小的数
 * @Description TODO
 * @Date 2022/12/9 22:36
 * @Created by xjl
 */
public class JZ45把数组排成最小的数 {
    public String minNumber(int[] nums) {
        String[] strs = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            strs[i] = String.valueOf(nums[i]);
        }
        Arrays.sort(strs, (x, y) -> (x + y).compareTo(y + x));
        StringBuilder res = new StringBuilder();
        for (String s : strs) {
            res.append(s);
        }
        return res.toString();
    }
}
